//
//  DHAllRadioTableViewCell.m
//  Moment
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 谭泽源. All rights reserved.
//

#import "DHAllRadioTableViewCell.h"

@implementation DHAllRadioTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

-(void)createViews{
    _titleImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_titleImageView];
    _titleLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_titleLabel];
    _userNameLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_userNameLabel];
    _descirbeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_descirbeLabel];
    _soundsLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_soundsLabel];
    _boolNewImageView = [[UIImageView alloc]init];
    [_titleImageView addSubview:_boolNewImageView];
    _soundImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_soundImageView];
}
-(void)setRadio:(DHRadio *)radio{
    if (_radio != radio) {
        _radio = radio;
    }
    
[_titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(@8);
    make.left.equalTo(@5);
    make.bottom.equalTo(@-8);
    make.width.equalTo(_titleImageView.mas_height);
}];
    NSURL *url = [NSURL URLWithString:_radio.coverimg];
    [_titleImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"zanwei"]];
    if (_radio.isnew) {
        [_boolNewImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleImageView.mas_top).offset(0);
            make.left.equalTo(_titleImageView.mas_left).offset(0);
            make.width.equalTo(_titleImageView.mas_width).multipliedBy(0.33);
            make.height.equalTo(_titleImageView.mas_height).multipliedBy(0.33);
         }];
        _boolNewImageView.image = [UIImage imageNamed:@"new"];
        _boolNewImageView.hidden = NO;
    }else {
        _boolNewImageView.hidden = YES;
     }
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleImageView.mas_right).offset(8);
        make.top.equalTo(@8);
        make.width.equalTo(_titleImageView.mas_width).multipliedBy(2);
        make.height.equalTo(_titleImageView.mas_height).multipliedBy(0.33);
    }];
    _titleLabel.text = _radio.title;
    _titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    _titleLabel.textColor = [UIColor colorWithWhite:0.195 alpha:1.000];
    [_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(0);
        make.left.equalTo(_titleImageView.mas_right).offset(8);
        make.width.equalTo(_titleImageView.mas_width).multipliedBy(2);
        make.height.equalTo(_titleImageView.mas_height).multipliedBy(0.33);
    }];
    _userNameLabel.text = [NSString stringWithFormat:@"by:%@",radio.UserInfo.uname];
    _userNameLabel.font = [UIFont systemFontOfSize:10];
    _userNameLabel.textColor = [UIColor colorWithRed:0.664 green:0.932 blue:1.000 alpha:1.000];
    [_descirbeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_userNameLabel.mas_bottom).offset(0);
        make.left.equalTo(_titleImageView.mas_right).offset(8);
        make.width.equalTo(_titleImageView.mas_width).multipliedBy(2);
        make.height.equalTo(_titleImageView.mas_height).multipliedBy(0.33);
    }];
//    NSLog(@"radio.userinfo == %@",_radio.UserInfo.uname);
    _descirbeLabel.text = _radio.desc;
    _descirbeLabel.font = [UIFont systemFontOfSize:10];
    _descirbeLabel.textColor = [UIColor grayColor];
 
   
    [_soundsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@13);
        make.right.equalTo(@-5);
        make.width.equalTo(_titleImageView.mas_width).multipliedBy(0.8);
        make.height.equalTo(_soundImageView.mas_height).multipliedBy(1);
    }];
    _soundsLabel.text = [NSString stringWithFormat: @"%ld",_radio.count];
    _soundsLabel.font = [UIFont systemFontOfSize:10];
    _soundsLabel.textColor = [UIColor grayColor];
    
    [_soundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@13);
        make.right.equalTo(_soundsLabel.mas_left).offset(-3);
        make.width.and.height.equalTo(@15);
    }];
    _soundImageView.image = [UIImage imageNamed:@"iconfont-shengyin"];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
